package com.itheima.springbootwebtlias.mapper;


import com.github.pagehelper.Page;
import com.itheima.springbootwebtlias.pojo.ClaQueryParam;
import com.itheima.springbootwebtlias.pojo.Clazz;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Mapper
public interface ClazzMapper {

    //添加班级
    @Insert("insert into clazz (id, name, room, begin_date, end_date, master_id, subject, create_time, update_time) values (null,#{name},#{room},#{beginDate},#{endDate},#{masterId},#{subject},#{createTime},#{updateTime})")
    void saveClazz(Clazz clazz);

    //查询所有班级
    @Select("select * from clazz")
    List<Clazz> findAll();

    //分页查询，根据 班级名称 以及 课程的 开始时间和结束时间查询
    List<Clazz> selectByCondition(ClaQueryParam claQueryParam);


    //删除班级
    @Delete("delete from clazz where id = #{id}")
    void delClazz(Integer id);

    //根据id查询班级,根据班级学生的数量，判断是否可以删除
    @Select("select count(*) from student where clazz_id = #{id}")
    Integer selectCountsById(Integer id);

    //根据id查询班级+回显
    // '学科, 1:java, 2:前端, 3:大数据, 4:Python, 5:Go, 6: 嵌入式'
    @Select("select * from clazz where id = #{id}")
    Clazz findById(Integer id);

    //修改班级,编辑功能
    void update(Clazz clazz);
}
